<?php
namespace app\admin\controller;

use app\common\Eldata;
use think\BaseController;
use app\admin\model\Proaccount;
use app\admin\model\Page;
use app\admin\model\User;

class Analyse extends BaseController
{

    protected $page_size = 50;

    public function getCopyDataCount()
    {
        $copyData=$this->app->view_datas->getDocCount($indexName, 1, new \stdClass());

        return json_decode($copyData)['count'];
    }

    public function getClickDataCount()
    {
      $copyData=$this->app->view_datas->getDocCount($indexName, 2, new \stdClass());

      return json_decode($copyData)['count'];
    }

    public function getCurDayVisitCount()
    {
        $start_time =time()-round(time() % 86400);
        $end_time = $start_time + 86399;

        return $this->app->data_views->getDocTimeCount('view_datas', 0, $start_time, $end_time);
    }

    public function getCopyAllData()
    {
        $page_num = $this->request->param('page_num');
        $page_size = $this->request->param('page_size') ? :$this->page_num;
        $indexName = "data_views";
        $indexType = 1;  //copy

        return $this->app->data_views->pageSearch($indexName, $indexType, $this->page_size, $page_num);
    }

    public function getClickAllData()
    {
        $page_num = $this->request->param('page_num');
        $page_size = $this->request->param('page_size')? :$this->page_num;
        $indexName = 'data_views';
        $indexType = 0;

        return $this->rapp->data_views->pageSearch($indexName, $indexType, $this->page_size, $page_num);
    }

    public function getAreaClickDataCount()
    {
        $query_area = $this->request->param('area');

        if($query_area ! == null){
            $areaClickData = $this->app->view_datas->getDocCountQ('view_datas', 0, [
                'should' => [
                    'match' => ['province' => $query_area]
                ],
                'should' => [
                    'match' => ['city' => $query_area]
                ],
                'should' => [
                    'match' => ['nation' => $query_area]
                ]
            ]);
        }else{
            return false;
        }

        return $areaClickData;
    }

    public function getNationClickDataCount()
    {
        $query_nation = $this->request->param('nation');

        if($query_nation !== null){
            $nationClickData = $this->app->view_datas->getDocCountQ('view_datas', 0, [
                'should' => [
                    'match' => ['nation' => $query_nation]
                ]
            ]);
        }else{
            return false;
        }

        return $nationClickData;
    }

    public function getProvinceClickDataCount()
    {
        $query_province = $this->request->param('province');

        if($query_province !== null){
            $provinceClickData = $this->app->view_datas->getDocCountQ('view_datas',0,[
                'should' => [
                    'match' => ['province' => $query_province]
                ]
            ]);
        }else{
            return false;
        }

        return $provinceClickData;
    }

    public function getCityClickDataCount()
    {
        $query_city = $this->request->param('city');

        if($query_city !== null){
            $cityClickData = $this->app->view_datas->getDocCountQ('view_datas',0,[
                'should' => [
                    'match' => ['city' => $query_city]
                ]
            ]);
        }else{
            return false;
        }

        return $cityClickData;
    }

    public function getNationCopyDataCount()
    {
        $query_nation = $this->request->param('nation');

        if($query_nation !== null){
            $nationCopyData = $this->app->view_datas->getDocCountQ('view_datas',0,[
                'should' => [
                    'match' => ['nation' => $query_nation]
                ]
            ]);
        }else{
            return false;
        }

        return $nationCopyData;
    }

    public function getProvinceCopyDataCount()
    {
        $query_province = $this->request->param('province');

        if($query_province !== null){
            $provinceCopyData = $this->app->view_datas->getDocCountQ('view_datas',0,[
                'should' => [
                    'match' => ['province' => $query_province]
                ]
            ]);
        }else{
            return false;
        }

        return $provinceCopyData;
    }

    public function getCityCopyDataCount()
    {
        $query_city = $this->request->param('city');

        if($query_city !== null){
            $cityCopyData = $this->app->view_datas->getDocCountQ('view_datas',0,[
                'should' => [
                    'match' => ['city' => $query_city]
                ]
            ]);
        }else{
            return false;
        }

        return $cityCopyData;
    }

    public function getTop50Keywords()
    {
        $index = 'view_datas';
        $type = 1;
        $count = 50;
        $sort = [
            'count' => [
                'order' => 'desc'
            ]
        ];
        $query = [
           'match_all' => new \stdClass(),
        ];

        return $this->app->view_datas->getSortDoc($index, $type, $count, $sort, $query);
    }

    public function getCopyClickDataAccount()
    {

    }

}
